<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/admincontent.jsp" %>
<link rel="stylesheet" href="/resources/js/plugins/kindeditor-4.1.10/themes/default/default.css"/>
<div id="Content" style="display: flex;">
    <div style="height: 100%; width: 100px;flex: 15%;">
        <div id="checkTemplate">
            <div id="searchbox" >
                <div class="layui-form-item searchform" style="border: none">
                    <div class="layui-inline" style="margin-right: 0px;">
                        <input type="text" name="search_jobname" id="search_jobname" placeholder="请输入" autocomplete="on" class="layui-input" style="width: 130px;height: 26px;">
                    </div>
                    <div class="layui-inline" style="margin-right: 0px;">
                        <button id="flows_searchbtn" type="button" class="search"></button>
                    </div>
                </div>
            </div>

            <table class="treeTable inputform searchform" id="tempsTable">
                <tbody>
                ${jobtemps}
                </tbody>
            </table>
        </div>

    </div>
    <div style="flex: 85%;">
    <form class="jobform" method="post" id="jobform" >
        <input type="hidden" name="pid" value="${pid}"/>
        <input type="hidden" name="id" value="${id}"/>
        <input type="hidden" name="tempsavetype" id="tempsavetype" />
        <input type="hidden" name="tempid" id="tempid" />
        <input type="hidden" name="ptype" id="ptype" value="${ptype}"/>
        <table class="treeTable inputform searchform">
            <thead>
            <tr>
                <td>岗位名称<span class="required"> * </span></td>
                <td colspan="3">
                    <div><input type="text" name="jobname" id="jobname" datatype="*" nullmsg="岗位不能为空！"/></div>
                </td>
                <td></td>
                <td style="text-align:right;">招聘人数<span class="required"> * </span></td>
                <td>
                    <div style="width:200px;"><input type="text" name="zpcount" id="zpcount" datatype="*" nullmsg="招聘人数不能为空！"/>
                    </div>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>学历要求<span class="required"> * </span></td>
                <td colspan="3">
                    <div>
                        <select name="educode" id="educode" datatype="*" nullmsg="学历不能为空！">
                            <option value="0">不限</option>
                            <option value="10">博士研究生</option>
                            <option value="11">全日制硕士研究生</option>
                            <option value="14">普通全日制本科</option>
                            <option value="15">国民教育本科</option>
                        </select>
                        <input type="hidden" name="eduname" id="eduname"/>
                    </div>
                </td>
                <td></td>
                <td style="text-align:right;">专业要求<span class="required"> * </span></td>
                <td>
                    <div style="width:200px;">
                        <input type="text" name="major" id="major" datatype="*" nullmsg="所学专业不能为空！"/>
                    </div>
                </td>
                <td></td>
            </tr>
            <tr>
                <td width="120">年龄要求</td>
                <td width="80">
                    <div>
                        <input type="text" name="agef" id="agef"/>
                    </div>
                </td>
                <td width="20" style="text-align:center">-</td>
                <td width="80">
                    <div>
                        <input type="text" name="aget" id="aget"/>
                    </div>
                </td>
                <td width="190" style="text-align:left;">请填写数字,无要求请留空</td>
                <td width="120" style="text-align:right;">性别要求<span class="required"> * </span></td>
                <td width="200">
                    <div>
                        <select name="gender" id="gender">
                            <option value="不限">不限</option>
                            <option value="男">男</option>
                            <option value="女">女</option>
                        </select>
                    </div>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>身高要求</td>
                <td colspan="3">
                    <div><input type="text" name="height" id="height"/></div>
                </td>
                <td style="text-align:left;">填最低身高(单位:CM),无要求留空</td>
                <td style="text-align:right;">视力要求</td>
                <td>
                    <div><input type="text" name="vision" id="vision"/></div>
                </td>
                <td>无要求请留空</td>
            </tr>
            <tr>
                <td>工作年限</td>
                <td colspan="3">
                    <div><input type="text" name="workyear" id="workyear"/></div>
                </td>
                <td style="text-align:left;">填最低工龄(单位:年),无要求留空</td>
                <td style="text-align:right;">保存为模版</td>
                <td>
                    <div style="text-align: left;" id="istemplate">
                        <input type="radio" name="istemplate"  value="NO"  checked/>不保存
                        <input type="radio" name="istemplate"  value="YES"  />保存
                        <!--<select name="istemplate" id="istemplate">
                            <option value="NO">不保存</option>
                            <option value="YES">保存</option>
                        </select>-->
                    </div>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>工作职责<span class="required"> * </span></td>
                <td colspan="7">
                    <div class="htmleditor">
                        <textarea id="workcont" name="workcont" datatype="*" nullmsg="工作职责不能为空！"
                                  style="width:737px;height:200px;"></textarea>
                    </div>
                </td>
            </tr>
            <tr>
                <td>工作经验及技能要求<span class="required"> * </span></td>
                <td colspan="7">
                    <div class="htmleditor">
                        <textarea id="workreq" name="workreq" datatype="*" nullmsg="工作经验及技能要求不能为空！"
                                  style="width:737px;height:200px;"></textarea>
                    </div>
                </td>
            </tr>
            <tr>
                <td></td>
                <td colspan="8">
                    <button type="submit" class="save" >添 加</button>
                </td>
            </tr>
            </thead>
        </table>
    </form>
    </div>
</div>
<link rel="stylesheet" href="/resources/js/plugins/layui/css/layui.css" />
<script src="/resources/js/plugins/layui/layui.all.js" type="text/javascript"></script>
<script charset="utf-8" src="/resources/js/plugins/kindeditor-4.1.10/kindeditor-min.js"></script>
<script charset="utf-8" src="/resources/js/plugins/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {
        var $ = layui.$
            , layer = layui.layer
            , form = layui.form;

    });

    $.fn.serializeObject = function()
    {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

    //实例化编辑器
    var szcont, szreq, nzcont, nzreq;
    KindEditor.ready(function (K) {
        szcont = K.create('#workcont', {
            resizeType: 1,
            items: ['removeformat', 'fullscreen'],
            afterBlur: function () {
                this.sync();
            }
        });
        szreq = K.create('#workreq', {
            resizeType: 1,
            items: ['removeformat', 'fullscreen'],
            afterBlur: function () {
                this.sync();
            }
        });
    });

    $(document).ready(function () {

        $('#flows_searchbtn').click(function () {
            var tempname=$('#search_jobname').val();
            var ptype=$('#ptype').val();
            var state="启用";
            layer.load();
            $.post('/ProjectJobTemplate/findByName',{"tempName":tempname,"ptype":ptype,"state":state},function (data) {
                layer.closeAll();
                if(data.state){
                    if(data.datas!=null){
                        $('#tempsTable tbody').empty();
                        var  temps=data.datas;
                        $(temps).each(function (index,temp) {
                            var tr=$("<tr><td id='jobtemp_"+temp.id+"'>"+temp.tempname+"</td></tr>");
                            tr.on('click',function(){trClikcHandle(this)});
                            $('#tempsTable tbody').append(tr)
                        });
                    }

                }else{
                    if(data.Message!=null){
                        layer.alert(data.Message);
                    }else{
                        layer.alert(data.message);
                    }
                }
            },"JSON")
        });


        $(".jobform").Validform({
            datatype: {
                //大于等于0的整数
                "zzs": /^([1-9]\d{0,}|0)$/,
            },
            callback:function (data) {
               var projectJob= $(data).serializeObject();
               var projectJobList=parent.jobList;
               if(projectJob!=undefined){
                   var savetemp = $("input[name='istemplate']:checked").val();
                   if(savetemp=="YES"){
                       $.post('/ProjectJobTemplate/saveOrUpdate',projectJob,function (data) {
                           if(data.state){
                               projectJobList.push(projectJob);
                               layer.msg('操作成功!', {
                                   icon: 1,
                                   time: 2000 //2秒关闭（如果不配置，默认是3秒）
                               }, function(){
                                   var index=parent.layer.getFrameIndex(window.name);
                                   parent.fullJobList();
                                   parent.layer.close(index);
                               });
                           }else{
                               if(data.Message!=null){
                                   layer.alert(data.Message);
                               }else{
                                   layer.alert(data.message);
                               }
                           }
                       },"JSON");

                   }else{
                       projectJobList.push(projectJob);
                       layer.msg('操作成功!', {
                           icon: 1,
                           time: 2000 //2秒关闭（如果不配置，默认是3秒）
                       }, function(){
                           var index=parent.layer.getFrameIndex(window.name);
                           parent.fullJobList();
                           parent.layer.close(index);
                       });
                   }

               }
                return false;
            }
        });
        $('input[name=eduname]').val($('select[name=educode]').find("option:selected").text());
        $('select[name=educode]').change(function () {
            $('input[name=eduname]').val($('select[name=educode]').find("option:selected").text());
        });
        $('#jobname').blur(function () {
            var jobList=parent.jobList;
            if(jobList.length>0){
                for(var i=0;i<jobList.length;i++){
                    var job=jobList[i];
                    var itext=$(this).val();
                    if(job.jobname==itext){
                        layer.msg('岗位名称重复!', {
                            icon: 2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        },function () {
                            $('#jobname').val('');
                            $('#jobname').focus();
                        });
                        break;
                    }
                }
            }
        });

        $('#istemplate input[type=radio]').change(function () {
            var istemp=$(this).val();
            if(istemp=="YES"){
                $('#tempsavetype').val("new")
            }else{
                $('#tempsavetype').val("");
            }
        });
    });
    function trClikcHandle(tr) {
        var cid=$(tr).children("td").attr("id");
        var tempId=cid.replace("jobtemp_","");
        layer.load();
        $.get('/ProjectJobTemplate/getJobTemplate',{'tempid':tempId},function (data) {
            //console.log(data);
            layer.closeAll();
            if(data.state){
                if(data.datas!=null){
                    job=data.datas;
                    $('#jobname').val(job.jobname);
                    $('#gender').val(job.gender);
                    $('#vision').val(job.vision);
                    $('#agef').val(job.agef);
                    $('#aget').val(job.aget);
                    $('#zpcount').val(job.zpcount);
                    $('#educode').val(job.educode);
                    $('#eduname').val(job.eduname);
                    $('#major').val(job.major);
                    $('#height').val(job.height);
                    $('#workyear').val(job.workyear);
                    szcont.html(job.workcont);
                    szreq.html(job.workreq);
                    szcont.sync();
                    szreq.sync();
                }
            }else{
                layer.alert(data.message);
            }
        },'JSON')
    }

    $(function () {
        $('#flows_searchbtn').click();
    })
</script>
</body>
</html>